<template>
	<AbnormalTemplate :treeData="treeData" @treeHandle="treeHandle" :unInitTimmer="unInitTimmer" :datePickType="datePickType">
		<div slot="rightBtn">
			&nbsp;<el-button @click="downloadExcel">导出</el-button>
		</div>
		<Table
			:tableData="tableData"
			:tableHead="tableHead"
			:propKey="{ prop: 'id', label: 'name' }"
			:isUseSlot="false"
			:page="listQuery.page"
			:limit="listQuery.limit"
			v-loading="listLoading"
		>
			<template slot="tool" slot-scope="{ data }">
				<el-button
					style="padding:3px;"
					v-if="data.row['status'] == '已处理'"
					icon="el-icon-search"
					@click="handleEdit(data.row)"
					type="text"
					>查看</el-button
				>
				<el-button
					v-else
					style="color:red;padding:3px;"
					icon="el-icon-document"
					@click="handleEdit(data.row)"
					type="text"
					>处理</el-button
				>
			</template>
		</Table>
		<Pagination
			v-show="total > 0"
			:total="total"
			:page.sync="listQuery.page"
			:limit.sync="listQuery.limit"
			@pagination="getList"
		></Pagination>
	</AbnormalTemplate>
</template>
<script>
import AbnormalTemplate from "@/template/abnormal.temp.vue";
import Table from "@/components/Table";
import Pagination from "@/components/Pagination"; // 分页
import { getAbnormalList } from "@/api/RCIM/RCIM-nuclearSafetyRanking";
import { ExportExcelAbnormal } from "@/api/RCIM/RCIM-downloadFile";
import moment from "moment";
export default {
	name: "KdHistoryData",
	components: { AbnormalTemplate, Table, Pagination },
	data() {
		return {
			treeData: {},
			total: 5,
			listLoading: true,
			// 调用表格接口参数
			listQuery: {
				page: 1,
				limit: 10,
				nodeId: "",
				startTime: "",
				endTime: "",
				isHandle: ""
			},
			datePickType: {
				precise: "datetimerange",
				format: "yyyy-MM-dd HH:mm",
			},
			tableData: [],
			// 表格头数据
			tableHead: [
				{
					id: "enterprise",
					name: "企业",
					width: ""
				},
				{
					id: "sourceCode",
					name: "源国家编码",
					width: "",
					align: "center"
				},
				{
					id: "applicationType",
					name: "应用类型",
					width: "",
					align: "center"
				},
				{
					id: "abnormalType",
					name: "异常类型",
					width: "",
					align: "center"
				},
				{
					id: "abnormalTime",
					name: "异常时间",
					width: "",
					align: "center"
				},
				{
					id: "abnormalSite",
					name: "异常地点",
					align: "center",
					width: ""
				},
				{
					id: "thenDose",
					name: "当时剂量",
					width: "",
					align: "center"
				},
				{
					id: "status",
					name: "状态",
					align: "center",
					width: ""
				},
				{
					id: "sourceType",
					name: "源类别",
					align: "center",
					width: ""
				},
				{
					id: "operate",
					name: "操作",
					align: "center",
					width: ""
				}
			],
			unInitTimmer: false,
		};
	},
	mounted() {

	},
	created() {
		let route = this.$route.query;
		// 获取跳转参数
		if (route.isHandle !== undefined) {
			this.listQuery.isHandle = route.isHandle;
			this.unInitTimmer = true;
		}
	},
	methods: {
		/**
		 * @desc 导出表格
		 */
		downloadExcel() {
			this.$confirm("确认要导出为Excel吗？")
				.then(_ => {
					this.donloadLoading = true;
					this.getExcel({
						callback: ExportExcelAbnormal,
						params: this.listQuery,
						id: "abnormalSearch"
					})
						.then(res => {
							this.donloadLoading = false;
						})
						.catch(err => {
							this.donloadLoading = false;
						});
				})
				.catch(_ => {});
		},
		/**
		 * @desc 点击左侧树回调
		 * @param {Object} param 树节点数据
		 */
		treeHandle(param) {
			this.listQuery.nodeId = param.id;
			this.listQuery.nodeType = param.type;
			this.listQuery.startTime = param.startTime ? moment(param.startTime).format('YYYY-MM-DD HH:mm') : '';
			this.listQuery.endTime = param.endTime ? moment(param.endTime).format('YYYY-MM-DD HH:mm') : '';
			this.listQuery.treeType = param.treeType;
			this.getList();

		},
		/**
		 * @desc 点击表格详情按钮函数
		 * @param {Object} row 表格行数据
		 */
		handleEdit(row) {
			this.$router.push({
				path: "/RCIM-abnormalHandle",
				query: { id: row.id }
			});
		},
		/**
		 * @desc 获取表格数据
		 */
		async getList() {
			this.listLoading = true;
			const { data } = await getAbnormalList(this.listQuery);
			this.total = data.total;
			this.tableData = data.abnormalList;
			// 设置本地参数  详情调用
			sessionStorage.setItem(
				"abnormalList",
				JSON.stringify(this.tableData)
			);
			this.listQuery.isHandle = "";
			this.listLoading = false;
		}
	}
};
</script>

<style lang="scss" scoped></style>
